home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / arexx / ole1v10a.lha / OLE_System / ole / CatCompiler.ole next >
Encoding:
Text File  |  1995-02-10  |  3.4 KB  |  206 lines

  1. /*
  2.  * CatCompiler.ole
  3.  *
  4.  * USAGE: called from the "Configure.ole" module
  5.  *
  6.  * A catalog compiler used for the OLE system. It read the catalog
  7.  * description and write out different files, one for each language. The
  8.  * compiled catalog will be stored in the appropriate directory.
  9.  *
  10.  * HISTORY:
  11.  * v1.01    now each string is "þIDþstring linesÞ"
  12.  *
  13.  * v1.02    a minor update to follow OLE Server v1.10
  14.  *
  15.  * v1.03    now this is an OLE module
  16.  *
  17.  * TODO:    put all messages in the localization file
  18.  *
  19.  * $(C): (1994, Rocco Coluccelli, Bologna)
  20.  * $VER: CatCompiler.ole 1.03 (03.Dec.1994)
  21.  */
  22.  
  23. OPTIONS RESULTS
  24.  
  25. PARSE ARG oleclip
  26. PARSE VALUE GETCLIP(oleclip) WITH jobID modID . . . . . oleport olehost userscreen . . locale .
  27.  
  28. /*
  29.  *    strings and messages delimiters
  30.  */
  31. BS = "þ"    /* begin string */
  32. ES = "Þ"    /* end string */
  33. NL = '0A'x    /* new line */
  34.  
  35. /*
  36.  *    characters conversion table
  37.  */
  38. CO = ","    /* comma */
  39. VI = "¸"    /* virgola */
  40.  
  41. QU = "'"    /* quote */
  42. AP = "´"    /* apostrophe */
  43.  
  44. /*
  45.  *    Send commands to OLE server
  46.  */
  47. ADDRESS VALUE oleport
  48.  
  49. IF OPENPORT(olehost) == NULL() THEN DO
  50.     ERROR jobID modID 1 olehost
  51.     EXIT 10
  52.     END
  53.  
  54. INFO jobID modID 'locale.path'
  55. localepath = GETCLIP(oleclip)
  56.  
  57.  
  58. DO UNTIL cmd = 'QUIT'
  59.  
  60.     CALL WAITPKT(olehost)
  61.     pkt = GETPKT(olehost)
  62.  
  63.     IF pkt == NULL() THEN ITERATE
  64.  
  65.     PARSE VALUE GETARG(pkt) WITH cmd argv
  66.  
  67.     SELECT
  68.  
  69.         /*
  70.          *    COMPILE sourcecat
  71.          */
  72.         WHEN cmd = 'COMPILE' THEN CALL CompileCat(STRIP(argv,'B'))
  73.  
  74.         OTHERWISE NOP
  75.  
  76.     END
  77.  
  78.     CALL REPLY(pkt,0)
  79.  
  80. END
  81.  
  82. CALL CLOSEPORT(olehost)
  83. EXIT 0
  84.  
  85.  
  86. /*
  87.  *    procedure that compile the given catalog source file
  88.  *
  89.  *    CompileCat(sourcecat)
  90.  */
  91. CompileCat:
  92.  
  93.     destcat = SplitPath(LEFT(ARG(1),LENGTH(ARG(1)) - 3)) || '.catalog'
  94.  
  95.     IF ~OPEN(src,ARG(1),'R') THEN DO
  96.         ERROR jobID modID 5 ARG(1)
  97.         RETURN
  98.         END
  99.  
  100.     cat = 0        /* catalog flag */
  101.     str = 0        /* string flag */
  102.     DO UNTIL EOF(src)
  103.  
  104.         line = READLN(src)
  105.         PARSE VAR line head rest .
  106.  
  107.         SELECT
  108.  
  109.             /*
  110.              * skip comment lines
  111.              */
  112.             WHEN head = ';' THEN NOP
  113.  
  114.             /*
  115.              *    begin or end of catalog
  116.              */
  117.             WHEN head = '##' THEN DO
  118.  
  119.                 IF rest ~= '' & ~cat THEN DO
  120.  
  121.                     path = localepath || rest
  122.                     IF ~EXISTS(path) THEN CALL MAKEDIR(path)
  123.  
  124.                     IF ~OPEN(dst,path || '/' || destcat,'W') THEN DO
  125.                         CALL CLOSE(src)
  126.                         ERROR jobID modID 4 path || '/' || destcat
  127.                         RETURN
  128.                         END
  129.  
  130.                     CALL PostMsg(100,100,'Writing...\' || path || '/' || destcat '       \',userscreen)
  131.                     cat = 1
  132.                     END
  133.  
  134.                 ELSE DO
  135.                     string = Replace(string,CO,VI)
  136.                     string = Replace(string,QU,AP)
  137.                     CALL WRITELN(dst,string)
  138.                     CALL CLOSE(dst)
  139.                     CALL PostMsg(100,100,'finished\',userscreen)
  140.                     cat = 0
  141.                     END
  142.  
  143.                 string = ''
  144.             END
  145.  
  146.             /*
  147.              *    begin or end of string
  148.              */
  149.             WHEN head = '#' THEN DO
  150.  
  151.                 IF rest ~= '' & str = 0 THEN DO
  152.                     string = string || BS || UPPER(rest) || BS
  153.                     str = 1
  154.                     END
  155.  
  156.                 ELSE DO
  157.                     string = string || ES
  158.                     str = 0
  159.                     END
  160.  
  161.             END
  162.  
  163.             /*
  164.              *    add a new line to the valid string
  165.              */
  166.             WHEN str > 0 THEN DO
  167.  
  168.                 IF str = 2 THEN
  169.                     string = string || NL || line
  170.  
  171.                 ELSE DO
  172.                     string = string || line
  173.                     str = 2
  174.                     END
  175.             END
  176.  
  177.             /*
  178.              *    skip invalid lines
  179.              */
  180.             OTHERWISE NOP
  181.  
  182.         END
  183.     END
  184.  
  185.     CALL CLOSE(src)
  186.     CALL PostMsg()
  187.  
  188. RETURN
  189.  
  190.  
  191. Replace: PROCEDURE
  192. PARSE ARG line,old,new
  193.  
  194.     DO FOREVER
  195.         pos = POS(old,line)
  196.         IF pos = 0 THEN LEAVE
  197.         line = OVERLAY(new,line,pos)
  198.     END
  199.  
  200. RETURN line
  201.  
  202.  
  203. SplitPath:
  204.  
  205. RETURN SUBSTR(ARG(1),MAX(POS(':',ARG(1)),LASTPOS('/',ARG(1))) + 1)
  206.